/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ccpvMainPanel.java
 *
 * Created on Apr 28, 2009, 12:34:59 PM
 */
package CCPVSimulationRootPanelPackage;

import CoalitionCirclePackage.CCPVCoalitionCircleViewerPanel;
import SocialMatrixPackage.SocialMatrix;
import ExpandablePopupMenuPackage.*;
import GISPackage.CCPVGISPanelWithLegend;
import GISPackage.GISMenuItem;
import GISPackage.Region;
import GUIUtilities.TreeUtilities;
import RobertsCode.NamedArrayList;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Vector;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import multiarray.MultiArray;

/**
 *
 * @author Evan
 */
public class CCPVSimulationRootPanel extends javax.swing.JPanel
{

  /** Creates new form ccpvMainPanel */
  public CCPVSimulationRootPanel()
  {
    initComponents();
    // setup the matrix at least until the user changes it
    altruismMatrix = new SocialMatrix(ascriptiveTree);
    // setting up population based on this initial tree
    populationCounts = new MultiArray(altruismMatrix.getDimensions());
    // testing the set method
    altruismMatrix.setAllToValue(0.5);
    // setup coalition rules dialog
    coalitionRulesButtonGroup.add(coalitionRulesAdditionOption);
    coalitionRulesButtonGroup.add(coalitionRulesMultiplicationOption);
    // setup the drag bar panel
    //dragBarContainer.setSize(DEFAULT_DRAG_BAR_CONTAINER_SIZE);
    //theDragBarPanel.setSize(dragBarContainer.getSize());
    //Dimension size = dragBarContainer.getSize();
    //dragBarContainer.add(theDragBarPanel);
    setupTreeListeners();
    // initialize popup menu
    expMenu = new ExpandablePopupMenu(ascriptiveTree);
    regionDataDialog.setVisible(false);
    regionDataDialog.setSize(regionCoalitionDialogSize);
    regionDataDialog.setPreferredSize(regionCoalitionDialogSize);

    // seupt gis
    gis.setBounds(0, 0, 1500, 900);
    gis.readXmlFile("C:/CCPV Data/world files/world.kml");
    this.add(gis);
    gis.repaint();

    // setup coalition circle viewer
    coalitionCircleContainer.add(circlePanel);
    addRightClickListenerToGISPanel();

    // setup listeners for stepping through the simulation
    //setupSimulationStepListeners();
  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    createCoalitionDialog = new javax.swing.JDialog();
    jPanel3 = new javax.swing.JPanel();
    coalCreationRemoveCharacteristicButton = new javax.swing.JButton();
    coalCreationNextCoalButton = new javax.swing.JButton();
    coalitionCreationGroupRemovalText = new javax.swing.JTextField();
    jLabel7 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jScrollPane6 = new javax.swing.JScrollPane();
    coalitionCreationGroupPane = new javax.swing.JTextPane();
    jScrollPane7 = new javax.swing.JScrollPane();
    coalitionCreationOthersPane = new javax.swing.JTextPane();
    jScrollPane4 = new javax.swing.JScrollPane();
    coalitionCreationCoalitionPane = new javax.swing.JTextPane();
    jLabel4 = new javax.swing.JLabel();
    coalCreationConfirmGroupButton = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    jLabel9 = new javax.swing.JLabel();
    coalCreationPrevCoalButton = new javax.swing.JButton();
    coalitionCreationSelectedAscriptivePane = new javax.swing.JTextField();
    jLabel6 = new javax.swing.JLabel();
    jScrollPane3 = new javax.swing.JScrollPane();
    coalitionCreationAscriptiveTree = new javax.swing.JTree();
    coalCreationResetGroupButton = new javax.swing.JButton();
    coalCreationConfirmCharacteristicButton = new javax.swing.JButton();
    jScrollPane5 = new javax.swing.JScrollPane();
    coalitionCreationDetailsPane = new javax.swing.JTextPane();
    coalCreationRemoveGroupButton = new javax.swing.JButton();
    jLabel2 = new javax.swing.JLabel();
    optionsDialog = new javax.swing.JDialog();
    optionsDialogPane = new javax.swing.JPanel();
    viewAndChangeAltruismButton = new javax.swing.JButton();
    viewAscriptiveTreeButton = new javax.swing.JButton();
    jLabel10 = new javax.swing.JLabel();
    setCoalitionRulesButton = new javax.swing.JButton();
    createACoalitionButton = new javax.swing.JButton();
    setCoalitionRulesButton1 = new javax.swing.JButton();
    ascriptiveTreeDialog = new javax.swing.JDialog();
    jPanel2 = new javax.swing.JPanel();
    jScrollPane11 = new javax.swing.JScrollPane();
    ascriptiveTree = new javax.swing.JTree();
    jLabel16 = new javax.swing.JLabel();
    coalitionRulesDialog = new javax.swing.JDialog();
    jPanel4 = new javax.swing.JPanel();
    jLabel19 = new javax.swing.JLabel();
    jLabel20 = new javax.swing.JLabel();
    coalitionRulesOKButton = new javax.swing.JButton();
    coalitionRulesAdditionOption = new javax.swing.JRadioButton();
    coalitionRulesMultiplicationOption = new javax.swing.JRadioButton();
    coalitionRulesButtonGroup = new javax.swing.ButtonGroup();
    fileChooser = new javax.swing.JFileChooser();
    errorDialog = new javax.swing.JDialog();
    jPanel5 = new javax.swing.JPanel();
    errorDialogText = new javax.swing.JLabel();
    regionDataDialog = new javax.swing.JDialog();
    jPanel1 = new javax.swing.JPanel();
    previousYearButton = new javax.swing.JButton();
    jTabbedPane2 = new javax.swing.JTabbedPane();
    jScrollPane13 = new javax.swing.JScrollPane();
    coalitionTextPane = new javax.swing.JTextPane();
    jScrollPane12 = new javax.swing.JScrollPane();
    coalitionTree = new javax.swing.JTree();
    dataFileNameLabel = new javax.swing.JLabel();
    previousCoalitionButton = new javax.swing.JButton();
    nextCoalitionButton = new javax.swing.JButton();
    nextYearButton = new javax.swing.JButton();
    optionsButton = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    regionDataDetailsPane = new javax.swing.JTextArea();
    jLabel21 = new javax.swing.JLabel();
    coalitionCircleDialog = new javax.swing.JDialog();
    coalitionCircleContainer = new javax.swing.JPanel();

    createCoalitionDialog.setBackground(new java.awt.Color(204, 255, 255));
    createCoalitionDialog.setForeground(new java.awt.Color(204, 255, 255));

    jPanel3.setBackground(new java.awt.Color(242, 255, 255));

    coalCreationRemoveCharacteristicButton.setText("Remove Characteristic");
    coalCreationRemoveCharacteristicButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        coalCreationRemoveCharacteristicButtonActionPerformed(evt);
      }
    });

    coalCreationNextCoalButton.setText("Next >>");

    coalitionCreationGroupRemovalText.setText("Enter group number for removal");

    jLabel7.setFont(new java.awt.Font("Tahoma", 3, 11));
    jLabel7.setText("Selected Ascriptive Characteristic");

    jLabel5.setFont(new java.awt.Font("Tahoma", 3, 12));
    jLabel5.setText("Group Removal");

    jLabel3.setFont(new java.awt.Font("Tahoma", 3, 14));
    jLabel3.setText("Selected Coalition");

    jScrollPane6.setViewportView(coalitionCreationGroupPane);

    jScrollPane7.setViewportView(coalitionCreationOthersPane);

    coalitionCreationCoalitionPane.setEditable(false);
    jScrollPane4.setViewportView(coalitionCreationCoalitionPane);

    jLabel4.setFont(new java.awt.Font("Tahoma", 3, 14));
    jLabel4.setText("Coalition Details");

    coalCreationConfirmGroupButton.setText("Confirm Group");
    coalCreationConfirmGroupButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        coalCreationConfirmGroupButtonActionPerformed(evt);
      }
    });

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
    jLabel1.setText("Coalition Creation");

    jLabel9.setFont(new java.awt.Font("Tahoma", 3, 12));
    jLabel9.setText("Other Coalitions");

    coalCreationPrevCoalButton.setText("<< Previous");
    coalCreationPrevCoalButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        coalCreationPrevCoalButtonActionPerformed(evt);
      }
    });

    coalitionCreationSelectedAscriptivePane.setEditable(false);
    coalitionCreationSelectedAscriptivePane.setFont(new java.awt.Font("Tahoma", 1, 11));

    jLabel6.setFont(new java.awt.Font("Tahoma", 3, 12));
    jLabel6.setText("Selected Group");

    coalitionCreationAscriptiveTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
      public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
        coalitionCreationAscriptiveTreeValueChanged(evt);
      }
    });
    jScrollPane3.setViewportView(coalitionCreationAscriptiveTree);

    coalCreationResetGroupButton.setText("Reset Group");
    coalCreationResetGroupButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        coalCreationResetGroupButtonActionPerformed(evt);
      }
    });

    coalCreationConfirmCharacteristicButton.setText("Confirm Characteristic");
    coalCreationConfirmCharacteristicButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        coalCreationConfirmCharacteristicButtonActionPerformed(evt);
      }
    });

    coalitionCreationDetailsPane.setEditable(false);
    jScrollPane5.setViewportView(coalitionCreationDetailsPane);

    coalCreationRemoveGroupButton.setText("Remove Group");
    coalCreationRemoveGroupButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        coalCreationRemoveGroupButtonActionPerformed(evt);
      }
    });

    jLabel2.setFont(new java.awt.Font("Tahoma", 3, 14));
    jLabel2.setText("Ascriptive Tree");

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
      jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel3Layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel3Layout.createSequentialGroup()
            .addGap(210, 210, 210)
            .addComponent(jLabel1))
          .addGroup(jPanel3Layout.createSequentialGroup()
            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(110, 110, 110)
            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(80, 80, 80)
            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGroup(jPanel3Layout.createSequentialGroup()
            .addComponent(coalCreationResetGroupButton, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(230, 230, 230)
            .addComponent(coalCreationPrevCoalButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(10, 10, 10)
            .addComponent(coalCreationNextCoalButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGroup(jPanel3Layout.createSequentialGroup()
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(coalCreationConfirmGroupButton, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(coalCreationConfirmCharacteristicButton, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(coalCreationRemoveCharacteristicButton, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(coalitionCreationSelectedAscriptivePane, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGap(4, 4, 4)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(coalitionCreationGroupRemovalText, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(coalCreationRemoveGroupButton, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)))
                  .addGroup(jPanel3Layout.createSequentialGroup()
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)))))
            .addGap(10, 10, 10)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
              .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
              .addGroup(jPanel3Layout.createSequentialGroup()
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)))))
        .addContainerGap())
    );
    jPanel3Layout.setVerticalGroup(
      jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
          .addGroup(jPanel3Layout.createSequentialGroup()
            .addComponent(jLabel5)
            .addGap(5, 5, 5)
            .addComponent(coalitionCreationGroupRemovalText, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(coalCreationRemoveGroupButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGroup(jPanel3Layout.createSequentialGroup()
            .addComponent(jLabel1)
            .addGap(11, 11, 11)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jLabel2)
              .addComponent(jLabel3)
              .addComponent(jLabel4))
            .addGap(3, 3, 3)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel3Layout.createSequentialGroup()
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 2, Short.MAX_VALUE)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addGap(6, 6, 6)
                .addComponent(coalitionCreationSelectedAscriptivePane, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(coalCreationConfirmCharacteristicButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(coalCreationRemoveCharacteristicButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20)
                .addComponent(jLabel6)
                .addGap(5, 5, 5)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(coalCreationConfirmGroupButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10))
              .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 495, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(coalCreationResetGroupButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(coalCreationPrevCoalButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(coalCreationNextCoalButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))))
        .addContainerGap())
    );

    javax.swing.GroupLayout createCoalitionDialogLayout = new javax.swing.GroupLayout(createCoalitionDialog.getContentPane());
    createCoalitionDialog.getContentPane().setLayout(createCoalitionDialogLayout);
    createCoalitionDialogLayout.setHorizontalGroup(
      createCoalitionDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );
    createCoalitionDialogLayout.setVerticalGroup(
      createCoalitionDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );

    optionsDialog.setBackground(new java.awt.Color(204, 255, 204));
    optionsDialog.setForeground(new java.awt.Color(255, 204, 204));

    optionsDialogPane.setBackground(new java.awt.Color(204, 255, 255));
    optionsDialogPane.setMinimumSize(new java.awt.Dimension(288, 201));
    optionsDialogPane.setLayout(null);

    viewAndChangeAltruismButton.setText("View or Change Group Altruism Values");
    viewAndChangeAltruismButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        viewAndChangeAltruismButtonActionPerformed(evt);
      }
    });
    optionsDialogPane.add(viewAndChangeAltruismButton);
    viewAndChangeAltruismButton.setBounds(10, 70, 270, 30);

    viewAscriptiveTreeButton.setText("View Ascriptive Characteristics Tree");
    viewAscriptiveTreeButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        viewAscriptiveTreeButtonActionPerformed(evt);
      }
    });
    optionsDialogPane.add(viewAscriptiveTreeButton);
    viewAscriptiveTreeButton.setBounds(10, 30, 270, 30);

    jLabel10.setFont(new java.awt.Font("Tahoma", 3, 18));
    jLabel10.setText("Options");
    optionsDialogPane.add(jLabel10);
    jLabel10.setBounds(100, 0, 150, 22);

    setCoalitionRulesButton.setText("View Altruism Social Net");
    setCoalitionRulesButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        setCoalitionRulesButtonActionPerformed(evt);
      }
    });
    optionsDialogPane.add(setCoalitionRulesButton);
    setCoalitionRulesButton.setBounds(10, 190, 270, 30);

    createACoalitionButton.setText("Create A Coalition");
    createACoalitionButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        createACoalitionButtonActionPerformed(evt);
      }
    });
    optionsDialogPane.add(createACoalitionButton);
    createACoalitionButton.setBounds(10, 110, 270, 30);

    setCoalitionRulesButton1.setText("Set Coalition Rules");
    setCoalitionRulesButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        setCoalitionRulesButton1ActionPerformed(evt);
      }
    });
    optionsDialogPane.add(setCoalitionRulesButton1);
    setCoalitionRulesButton1.setBounds(10, 150, 270, 30);

    javax.swing.GroupLayout optionsDialogLayout = new javax.swing.GroupLayout(optionsDialog.getContentPane());
    optionsDialog.getContentPane().setLayout(optionsDialogLayout);
    optionsDialogLayout.setHorizontalGroup(
      optionsDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(optionsDialogPane, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE)
    );
    optionsDialogLayout.setVerticalGroup(
      optionsDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(optionsDialogPane, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
    );

    ascriptiveTreeDialog.setMinimumSize(new java.awt.Dimension(292, 388));

    jPanel2.setBackground(new java.awt.Color(204, 255, 204));

    jScrollPane11.setViewportView(ascriptiveTree);

    jLabel16.setFont(new java.awt.Font("Tahoma", 1, 14));
    jLabel16.setText("Ascriptive Tree");

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jScrollPane11, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addGroup(jPanel2Layout.createSequentialGroup()
            .addGap(80, 80, 80)
            .addComponent(jLabel16)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addContainerGap())
    );
    jPanel2Layout.setVerticalGroup(
      jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel2Layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jLabel16)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap())
    );

    javax.swing.GroupLayout ascriptiveTreeDialogLayout = new javax.swing.GroupLayout(ascriptiveTreeDialog.getContentPane());
    ascriptiveTreeDialog.getContentPane().setLayout(ascriptiveTreeDialogLayout);
    ascriptiveTreeDialogLayout.setHorizontalGroup(
      ascriptiveTreeDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 292, Short.MAX_VALUE)
    );
    ascriptiveTreeDialogLayout.setVerticalGroup(
      ascriptiveTreeDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );

    coalitionRulesDialog.setMinimumSize(new java.awt.Dimension(207, 162));

    jPanel4.setBackground(new java.awt.Color(255, 255, 204));
    jPanel4.setMinimumSize(new java.awt.Dimension(207, 162));
    jPanel4.setLayout(null);

    jLabel19.setFont(new java.awt.Font("Tahoma", 1, 24));
    jLabel19.setText("Coalition Rules");
    jPanel4.add(jLabel19);
    jLabel19.setBounds(10, 10, 180, 30);

    jLabel20.setFont(new java.awt.Font("Tahoma", 2, 12));
    jLabel20.setText("Altruism Aggregate Function");
    jPanel4.add(jLabel20);
    jLabel20.setBounds(10, 50, 160, 15);

    coalitionRulesOKButton.setText("OK");
    coalitionRulesOKButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        coalitionRulesOKButtonActionPerformed(evt);
      }
    });
    jPanel4.add(coalitionRulesOKButton);
    coalitionRulesOKButton.setBounds(10, 120, 190, 30);

    coalitionRulesAdditionOption.setBackground(new java.awt.Color(255, 255, 204));
    coalitionRulesAdditionOption.setFont(new java.awt.Font("Tahoma", 1, 11));
    coalitionRulesAdditionOption.setText("Addition");
    jPanel4.add(coalitionRulesAdditionOption);
    coalitionRulesAdditionOption.setBounds(10, 70, 100, 23);

    coalitionRulesMultiplicationOption.setBackground(new java.awt.Color(255, 255, 204));
    coalitionRulesMultiplicationOption.setFont(new java.awt.Font("Tahoma", 1, 11));
    coalitionRulesMultiplicationOption.setText("Multiplication");
    jPanel4.add(coalitionRulesMultiplicationOption);
    coalitionRulesMultiplicationOption.setBounds(10, 90, 110, 23);

    javax.swing.GroupLayout coalitionRulesDialogLayout = new javax.swing.GroupLayout(coalitionRulesDialog.getContentPane());
    coalitionRulesDialog.getContentPane().setLayout(coalitionRulesDialogLayout);
    coalitionRulesDialogLayout.setHorizontalGroup(
      coalitionRulesDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
    );
    coalitionRulesDialogLayout.setVerticalGroup(
      coalitionRulesDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
    );

    jPanel5.setBackground(new java.awt.Color(255, 204, 204));

    errorDialogText.setFont(new java.awt.Font("Tahoma", 0, 14));
    errorDialogText.setText("Error in loading file.  Please try a different file.");

    javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
    jPanel5.setLayout(jPanel5Layout);
    jPanel5Layout.setHorizontalGroup(
      jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel5Layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(errorDialogText, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
        .addContainerGap())
    );
    jPanel5Layout.setVerticalGroup(
      jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel5Layout.createSequentialGroup()
        .addGap(35, 35, 35)
        .addComponent(errorDialogText, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(48, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout errorDialogLayout = new javax.swing.GroupLayout(errorDialog.getContentPane());
    errorDialog.getContentPane().setLayout(errorDialogLayout);
    errorDialogLayout.setHorizontalGroup(
      errorDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );
    errorDialogLayout.setVerticalGroup(
      errorDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );

    jPanel1.setBackground(new java.awt.Color(218, 221, 255));
    jPanel1.setMaximumSize(new java.awt.Dimension(526, 495));
    jPanel1.setMinimumSize(new java.awt.Dimension(526, 495));
    jPanel1.setLayout(null);

    previousYearButton.setFont(new java.awt.Font("Tahoma", 1, 11));
    previousYearButton.setText("<< See Previous Year's Results <<");
    jPanel1.add(previousYearButton);
    previousYearButton.setBounds(10, 220, 290, 30);

    jScrollPane13.setViewportView(coalitionTextPane);

    jTabbedPane2.addTab("Text View", jScrollPane13);

    jScrollPane12.setViewportView(coalitionTree);

    jTabbedPane2.addTab("Tree View", jScrollPane12);

    jPanel1.add(jTabbedPane2);
    jTabbedPane2.setBounds(10, 290, 620, 290);

    dataFileNameLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
    dataFileNameLabel.setText("File name of data will display here");
    jPanel1.add(dataFileNameLabel);
    dataFileNameLabel.setBounds(10, 10, 190, 14);

    previousCoalitionButton.setFont(new java.awt.Font("Tahoma", 1, 11));
    previousCoalitionButton.setText("<< See Previous Coalition <<");
    previousCoalitionButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        previousCoalitionButtonActionPerformed(evt);
      }
    });
    jPanel1.add(previousCoalitionButton);
    previousCoalitionButton.setBounds(10, 580, 300, 30);

    nextCoalitionButton.setFont(new java.awt.Font("Tahoma", 1, 11));
    nextCoalitionButton.setText(">> See Next Coalition >>");
    jPanel1.add(nextCoalitionButton);
    nextCoalitionButton.setBounds(330, 580, 300, 30);

    nextYearButton.setFont(new java.awt.Font("Tahoma", 1, 11));
    nextYearButton.setText(">> See Next Year's Results >>");
    jPanel1.add(nextYearButton);
    nextYearButton.setBounds(320, 220, 310, 30);

    optionsButton.setFont(new java.awt.Font("Tahoma", 1, 11));
    optionsButton.setText("Options");
    optionsButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        optionsButtonActionPerformed(evt);
      }
    });
    jPanel1.add(optionsButton);
    optionsButton.setBounds(520, 0, 110, 23);

    regionDataDetailsPane.setColumns(20);
    regionDataDetailsPane.setRows(5);
    jScrollPane1.setViewportView(regionDataDetailsPane);

    jPanel1.add(jScrollPane1);
    jScrollPane1.setBounds(10, 30, 620, 190);

    jLabel21.setFont(new java.awt.Font("Tahoma", 1, 14));
    jLabel21.setText("Coalitions");
    jPanel1.add(jLabel21);
    jLabel21.setBounds(10, 264, 620, 20);

    javax.swing.GroupLayout regionDataDialogLayout = new javax.swing.GroupLayout(regionDataDialog.getContentPane());
    regionDataDialog.getContentPane().setLayout(regionDataDialogLayout);
    regionDataDialogLayout.setHorizontalGroup(
      regionDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 638, Short.MAX_VALUE)
      .addGroup(regionDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 638, Short.MAX_VALUE))
    );
    regionDataDialogLayout.setVerticalGroup(
      regionDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 618, Short.MAX_VALUE)
      .addGroup(regionDataDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 618, Short.MAX_VALUE))
    );

    coalitionCircleContainer.setBackground(new java.awt.Color(255, 255, 255));
    coalitionCircleContainer.setLayout(null);

    javax.swing.GroupLayout coalitionCircleDialogLayout = new javax.swing.GroupLayout(coalitionCircleDialog.getContentPane());
    coalitionCircleDialog.getContentPane().setLayout(coalitionCircleDialogLayout);
    coalitionCircleDialogLayout.setHorizontalGroup(
      coalitionCircleDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(coalitionCircleContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 1011, Short.MAX_VALUE)
    );
    coalitionCircleDialogLayout.setVerticalGroup(
      coalitionCircleDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(coalitionCircleContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE)
    );

    setBackground(new java.awt.Color(255, 255, 204));
    setMaximumSize(new java.awt.Dimension(526, 495));
    setMinimumSize(new java.awt.Dimension(526, 495));

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 819, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 495, Short.MAX_VALUE)
    );
  }// </editor-fold>//GEN-END:initComponents

    private void coalCreationConfirmCharacteristicButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_coalCreationConfirmCharacteristicButtonActionPerformed
    {//GEN-HEADEREND:event_coalCreationConfirmCharacteristicButtonActionPerformed
      // TODO add your handling code here:
      int index = TreeUtilities.getSelectedAscriptiveCategoryIndex(coalitionCreationAscriptiveTree);
      if (index != -1)
      {
        String selectedAscriptive = coalitionCreationSelectedAscriptivePane.getText();
        if (!selectedGroupStringVector.get(index).contains(selectedAscriptive))
        {
          selectedGroupStringVector.get(index).add(selectedAscriptive);
        }

        correctSelectedGroupVector();
        setCoaltionCreationGroupPane();
      }
}//GEN-LAST:event_coalCreationConfirmCharacteristicButtonActionPerformed

    private void coalCreationPrevCoalButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_coalCreationPrevCoalButtonActionPerformed
    {//GEN-HEADEREND:event_coalCreationPrevCoalButtonActionPerformed
      // TODO add your handling code here:
}//GEN-LAST:event_coalCreationPrevCoalButtonActionPerformed

    private void viewAscriptiveTreeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewAscriptiveTreeButtonActionPerformed
      // TODO add your handling code here:
      ascriptiveTreeDialog.setVisible(true);
    }//GEN-LAST:event_viewAscriptiveTreeButtonActionPerformed

    private void viewAndChangeAltruismButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_viewAndChangeAltruismButtonActionPerformed
    {//GEN-HEADEREND:event_viewAndChangeAltruismButtonActionPerformed
      // TODO add your handling code here:
      //altruismDialog.setVisible(true);
}//GEN-LAST:event_viewAndChangeAltruismButtonActionPerformed

    private void setCoalitionRulesButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_setCoalitionRulesButtonActionPerformed
    {//GEN-HEADEREND:event_setCoalitionRulesButtonActionPerformed
      // TODO add your handling code here:
      coalitionRulesDialog.setVisible(true);
    }//GEN-LAST:event_setCoalitionRulesButtonActionPerformed

    private void coalitionRulesOKButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_coalitionRulesOKButtonActionPerformed
    {//GEN-HEADEREND:event_coalitionRulesOKButtonActionPerformed
      // TODO add your handling code here:
      coalitionRulesDialog.setVisible(false);
    }//GEN-LAST:event_coalitionRulesOKButtonActionPerformed

    private void coalitionCreationAscriptiveTreeValueChanged(javax.swing.event.TreeSelectionEvent evt)//GEN-FIRST:event_coalitionCreationAscriptiveTreeValueChanged
    {//GEN-HEADEREND:event_coalitionCreationAscriptiveTreeValueChanged
      // TODO add your handling code here:
      DefaultMutableTreeNode selected = (DefaultMutableTreeNode) coalitionCreationAscriptiveTree.getLastSelectedPathComponent();
      coalitionCreationSelectedAscriptivePane.setText((String) selected.getUserObject());
    }//GEN-LAST:event_coalitionCreationAscriptiveTreeValueChanged

    private void previousCoalitionButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_previousCoalitionButtonActionPerformed
    {//GEN-HEADEREND:event_previousCoalitionButtonActionPerformed
      // TODO add your handling code here:
}//GEN-LAST:event_previousCoalitionButtonActionPerformed

    private void optionsButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_optionsButtonActionPerformed
    {//GEN-HEADEREND:event_optionsButtonActionPerformed
      // TODO add your handling code here:
      optionsDialog.setVisible(true);
      optionsDialog.setSize(optionsDialogSize);
      optionsDialog.setPreferredSize(optionsDialogSize);

}//GEN-LAST:event_optionsButtonActionPerformed

    private void createACoalitionButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_createACoalitionButtonActionPerformed
    {//GEN-HEADEREND:event_createACoalitionButtonActionPerformed
      // TODO add your handling code here:
      createCoalitionDialog.setVisible(true);
      createCoalitionDialog.setSize(createCoaltionDialogSize);
      createCoalitionDialog.setPreferredSize(createCoaltionDialogSize);
}//GEN-LAST:event_createACoalitionButtonActionPerformed

    private void coalCreationRemoveCharacteristicButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_coalCreationRemoveCharacteristicButtonActionPerformed
    {//GEN-HEADEREND:event_coalCreationRemoveCharacteristicButtonActionPerformed
      // TODO add your handling code here:
      int index = TreeUtilities.getSelectedAscriptiveCategoryIndex(coalitionCreationAscriptiveTree);
      if (index != -1)
      {
        String selectedAscriptive = coalitionCreationSelectedAscriptivePane.getText();
        selectedGroupStringVector.get(index).remove(selectedAscriptive);

        correctSelectedGroupVector();
        setCoaltionCreationGroupPane();
      }
    }//GEN-LAST:event_coalCreationRemoveCharacteristicButtonActionPerformed

    private void coalCreationConfirmGroupButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_coalCreationConfirmGroupButtonActionPerformed
    {//GEN-HEADEREND:event_coalCreationConfirmGroupButtonActionPerformed
      // TODO add your handling code here:
      allSelectedGroups.add(selectedGroupStringVector);
      int numberOfAscriptives = selectedGroupStringVector.size();
      selectedGroupStringVector = new Vector<Vector<String>>();
      for (int i = 0; i < numberOfAscriptives; i++)
      {
        selectedGroupStringVector.add(new Vector<String>());
      }
      coalitionCreationGroupPane.setText("");
      setCoalitionCreationCoalitionPane();
    }//GEN-LAST:event_coalCreationConfirmGroupButtonActionPerformed

    private void coalCreationResetGroupButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_coalCreationResetGroupButtonActionPerformed
    {//GEN-HEADEREND:event_coalCreationResetGroupButtonActionPerformed
      // TODO add your handling code here:
      for (Vector<String> v : selectedGroupStringVector)
      {
        v.clear();
      }

      coalitionCreationGroupPane.setText("");
      setCoalitionCreationCoalitionPane();
    }//GEN-LAST:event_coalCreationResetGroupButtonActionPerformed

    private void coalCreationRemoveGroupButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_coalCreationRemoveGroupButtonActionPerformed
    {//GEN-HEADEREND:event_coalCreationRemoveGroupButtonActionPerformed
      // TODO add your handling code here:
      int index = Integer.parseInt(coalitionCreationGroupRemovalText.getText());
      allSelectedGroups.remove(index - 1);
      setCoalitionCreationCoalitionPane();
    }//GEN-LAST:event_coalCreationRemoveGroupButtonActionPerformed

    private void setCoalitionRulesButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_setCoalitionRulesButton1ActionPerformed
    {//GEN-HEADEREND:event_setCoalitionRulesButton1ActionPerformed
      // TODO add your handling code here:
    }//GEN-LAST:event_setCoalitionRulesButton1ActionPerformed

  // this is for when the tabs are created/etc.  it makes sure the drag bar panel reflects
  // what really should be shown.
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JTree ascriptiveTree;
  private javax.swing.JDialog ascriptiveTreeDialog;
  private javax.swing.JButton coalCreationConfirmCharacteristicButton;
  private javax.swing.JButton coalCreationConfirmGroupButton;
  private javax.swing.JButton coalCreationNextCoalButton;
  private javax.swing.JButton coalCreationPrevCoalButton;
  private javax.swing.JButton coalCreationRemoveCharacteristicButton;
  private javax.swing.JButton coalCreationRemoveGroupButton;
  private javax.swing.JButton coalCreationResetGroupButton;
  private javax.swing.JPanel coalitionCircleContainer;
  private javax.swing.JDialog coalitionCircleDialog;
  private javax.swing.JTree coalitionCreationAscriptiveTree;
  private javax.swing.JTextPane coalitionCreationCoalitionPane;
  private javax.swing.JTextPane coalitionCreationDetailsPane;
  private javax.swing.JTextPane coalitionCreationGroupPane;
  private javax.swing.JTextField coalitionCreationGroupRemovalText;
  private javax.swing.JTextPane coalitionCreationOthersPane;
  private javax.swing.JTextField coalitionCreationSelectedAscriptivePane;
  private javax.swing.JRadioButton coalitionRulesAdditionOption;
  private javax.swing.ButtonGroup coalitionRulesButtonGroup;
  private javax.swing.JDialog coalitionRulesDialog;
  private javax.swing.JRadioButton coalitionRulesMultiplicationOption;
  private javax.swing.JButton coalitionRulesOKButton;
  private javax.swing.JTextPane coalitionTextPane;
  private javax.swing.JTree coalitionTree;
  private javax.swing.JButton createACoalitionButton;
  private javax.swing.JDialog createCoalitionDialog;
  private javax.swing.JLabel dataFileNameLabel;
  private javax.swing.JDialog errorDialog;
  private javax.swing.JLabel errorDialogText;
  private javax.swing.JFileChooser fileChooser;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel10;
  private javax.swing.JLabel jLabel16;
  private javax.swing.JLabel jLabel19;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel20;
  private javax.swing.JLabel jLabel21;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel9;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JPanel jPanel3;
  private javax.swing.JPanel jPanel4;
  private javax.swing.JPanel jPanel5;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JScrollPane jScrollPane11;
  private javax.swing.JScrollPane jScrollPane12;
  private javax.swing.JScrollPane jScrollPane13;
  private javax.swing.JScrollPane jScrollPane3;
  private javax.swing.JScrollPane jScrollPane4;
  private javax.swing.JScrollPane jScrollPane5;
  private javax.swing.JScrollPane jScrollPane6;
  private javax.swing.JScrollPane jScrollPane7;
  private javax.swing.JTabbedPane jTabbedPane2;
  private javax.swing.JButton nextCoalitionButton;
  private javax.swing.JButton nextYearButton;
  private javax.swing.JButton optionsButton;
  private javax.swing.JDialog optionsDialog;
  private javax.swing.JPanel optionsDialogPane;
  private javax.swing.JButton previousCoalitionButton;
  private javax.swing.JButton previousYearButton;
  private javax.swing.JTextArea regionDataDetailsPane;
  private javax.swing.JDialog regionDataDialog;
  private javax.swing.JButton setCoalitionRulesButton;
  private javax.swing.JButton setCoalitionRulesButton1;
  private javax.swing.JButton viewAndChangeAltruismButton;
  private javax.swing.JButton viewAscriptiveTreeButton;
  // End of variables declaration//GEN-END:variables
  // my variables
  /*
   * VARIABLES FOR ALTRUISM DIALOG
   */
  private ExpandablePopupMenu expMenu;
  private SocialMatrix altruismMatrix;
  private Vector<String> ascriptiveCategories = new Vector<String>();
  // stores the populations
  MultiArray<Integer> populationCounts;
  private Dimension regionCoalitionDialogSize = new Dimension(550, 530);
  private Dimension createCoaltionDialogSize = new Dimension(635, 700);
  private Dimension optionsDialogSize = new Dimension(300, 300);
  private Dimension errorDialogSize = new Dimension(326, 116);
  private CCPVGISPanelWithLegend gis = new CCPVGISPanelWithLegend();
  // the selected group for group details
  private Vector<Vector<String>> selectedGroupStringVector = new Vector<Vector<String>>();
  // a reference social matrix only for reference info
  private SocialMatrix referenceSM;
  private Vector<Region> selectedRegions;
  private Point mouseClickPoint;
  private Vector<int[]> selectedCoalition = new Vector<int[]>();
  private Vector<Vector<Vector<String>>> allSelectedGroups = new Vector<Vector<Vector<String>>>();
  private CCPVCoalitionCircleViewerPanel circlePanel = new CCPVCoalitionCircleViewerPanel();
  private static final Dimension COALITION_CIRCLE_DIALOG_DEFAULT_SIZE = new Dimension(1000, 700);


  // Get methods
  // My methods

  // Sets up all tree listeners
  public void setupTreeListeners()
  {

    // These listeners are for group selection in other dialogs
    coalitionCreationAscriptiveTree.addTreeSelectionListener(new TreeSelectionListener()
    {

      public void valueChanged(TreeSelectionEvent e)
      {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) coalitionCreationAscriptiveTree.getLastSelectedPathComponent();

        /* if nothing is selected */
        if (node == null)
        {
          return;
        }

        /* retrieve the node that was selected */
        Object nodeInfo = node.getUserObject();

        /* React to the node selection. */
        // create buttons if there are children.
        coalitionCreationSelectedAscriptivePane.setText((String) nodeInfo);
      }
    });
  }


  // sets all the trees according to the input.
  // CURRENTLY DOES NOT HANDLE HEIERARCHIES
  public void setAllAscriptiveTrees(List<NamedArrayList<String>> ascriptives)
  {
    ascriptiveCategories = new Vector<String>();

    // all the roots
    DefaultMutableTreeNode tree1Root = (DefaultMutableTreeNode) ascriptiveTree.getModel().getRoot();
    DefaultMutableTreeNode tree2Root = (DefaultMutableTreeNode) coalitionCreationAscriptiveTree.getModel().getRoot();
//    DefaultMutableTreeNode tree3Root = (DefaultMutableTreeNode) groupAltruismTargetTree.getModel().getRoot();
    //   DefaultMutableTreeNode tree4Root = (DefaultMutableTreeNode) groupAltruismSourceTree.getModel().getRoot();

    tree1Root.removeAllChildren();
    tree2Root.removeAllChildren();
//    tree3Root.removeAllChildren();
    //  tree4Root.removeAllChildren();

    // iterate through the ascriptive categories
    for (int i = 0; i < ascriptives.size(); i++)
    {
      NamedArrayList<String> ascriptiveCategory = ascriptives.get(i);
      ascriptiveCategories.add(ascriptiveCategory.name);

      DefaultMutableTreeNode ascriptiveCategoryNode1 = new DefaultMutableTreeNode(ascriptiveCategory.name);
      DefaultMutableTreeNode ascriptiveCategoryNode2 = new DefaultMutableTreeNode(ascriptiveCategory.name);
      DefaultMutableTreeNode ascriptiveCategoryNode3 = new DefaultMutableTreeNode(ascriptiveCategory.name);
      DefaultMutableTreeNode ascriptiveCategoryNode4 = new DefaultMutableTreeNode(ascriptiveCategory.name);
      DefaultMutableTreeNode ascriptiveCategoryNode5 = new DefaultMutableTreeNode(ascriptiveCategory.name);

      for (int j = 0; j < ascriptiveCategory.size(); j++)
      {
        String categoryEntry = ascriptiveCategory.get(j);

        DefaultMutableTreeNode categoryEntryNode1 = new DefaultMutableTreeNode(categoryEntry);
        DefaultMutableTreeNode categoryEntryNode2 = new DefaultMutableTreeNode(categoryEntry);
        DefaultMutableTreeNode categoryEntryNode3 = new DefaultMutableTreeNode(categoryEntry);
        DefaultMutableTreeNode categoryEntryNode4 = new DefaultMutableTreeNode(categoryEntry);
        DefaultMutableTreeNode categoryEntryNode5 = new DefaultMutableTreeNode(categoryEntry);

        ascriptiveCategoryNode1.add(categoryEntryNode1);
        ascriptiveCategoryNode2.add(categoryEntryNode2);
        ascriptiveCategoryNode3.add(categoryEntryNode3);
        ascriptiveCategoryNode4.add(categoryEntryNode4);
        ascriptiveCategoryNode5.add(categoryEntryNode5);
      }

      tree1Root.add(ascriptiveCategoryNode1);
      tree2Root.add(ascriptiveCategoryNode2);
//      tree3Root.add(ascriptiveCategoryNode3);
    //     tree4Root.add(ascriptiveCategoryNode4);
    }

    ascriptiveTree.updateUI();
    coalitionCreationAscriptiveTree.updateUI();
    // groupAltruismTargetTree.updateUI();
    // groupAltruismSourceTree.updateUI();

    // if the trees change, we need to change the popup menu too
    expMenu = new ExpandablePopupMenu(ascriptiveTree);
    // add mouselisteners to the popup menu to avoid weird painting
    //  addPopupMouseListeners();
    expMenu.updateUI();

    // also have to change altruism matrix b/c it is dependent on the trees
    altruismMatrix = new SocialMatrix(ascriptiveTree);
    populationCounts = new MultiArray<Integer>(altruismMatrix.getDimensions());

    // setup the selection groups based on the ascriptives
    for (String s : ascriptiveCategories)
    {
      selectedGroupStringVector.add(new Vector<String>());
    }

    // setup reference sm
    referenceSM = new SocialMatrix(ascriptiveTree);
  }

  // sets the group details selected group pane according to the selected
  // gorup
  private void setCoaltionCreationGroupPane()
  {
    coalitionCreationGroupPane.setText(getGroupString(selectedGroupStringVector));
  }

  private void setCoalitionCreationCoalitionPane()
  {
    String newCoalitionText = "";

    for (int i = 0; i < allSelectedGroups.size(); i++)
    {
      Vector<Vector<String>> currentGroup = allSelectedGroups.get(i);
      String currentString = getGroupString(currentGroup);

      newCoalitionText += "Group #: " + (i + 1) + "\n";
      newCoalitionText += currentString + "\n";
    }

    coalitionCreationCoalitionPane.setText(newCoalitionText);
  }

  private String getGroupString(Vector<Vector<String>> input)
  {
    String newText = "";

    Vector<String> ascriptiveNames = referenceSM.getAscriptiveCategories();
    for (int i = 0; i < ascriptiveNames.size(); i++)
    {
      newText += ascriptiveNames.get(i) + ": ";
      Vector<String> selectedAscriptives = input.get(i);
      if (selectedAscriptives.size() > 0)
      {
        for (int j = 0; j < selectedAscriptives.size() - 1; j++)
        {
          newText += selectedAscriptives.get(j) + ", ";
        }
        newText += selectedAscriptives.get(selectedAscriptives.size() - 1);
      }
      else
      {
        newText += "any";
      }
      newText += "\n";
    }

    return newText;
  }

  private void addRightClickListenerToGISPanel()
  {
    gis.getGIS().addMouseListener(new java.awt.event.MouseAdapter()
    {

      public void mouseClicked(MouseEvent evt)
      {
        System.out.println("addrightclicklistenertogispanel called");
        mouseClickPoint = evt.getPoint();
        setupCircleListeners();
      }

      public void mousePressed(java.awt.event.MouseEvent evt)
      {
        mouseClickPoint = evt.getPoint();
      }
    });
  }

  private void setupCircleListeners()
  {
    Vector<GISMenuItem> allRegionMenuItems = gis.getAllRegionMenuItems();

    for (GISMenuItem g : allRegionMenuItems)
    {
      if (!g.circleListenerSet)
      {
        g.addActionListener(new java.awt.event.ActionListener()
        {

          public void actionPerformed(java.awt.event.ActionEvent evt)
          {
            System.out.println("heya!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            coalitionCircleDialog.setVisible(true);
            coalitionCircleDialog.setSize(COALITION_CIRCLE_DIALOG_DEFAULT_SIZE);
            coalitionCircleDialog.setPreferredSize(COALITION_CIRCLE_DIALOG_DEFAULT_SIZE);
          }
        });
      }
    }
  }

  private void setupRegionDialog(Region r)
  {
    // NEED TO DO LEO'S STUFF HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  }

  private Vector<int[]> removeDuplicates(Vector<int[]> input)
  {
    Vector<int[]> ret = new Vector<int[]>();

    for (int i = 0; i < input.size(); i++)
    {
      int[] candidate = input.get(i);

      // check if ret contains candidate
      boolean seen = false;
      for (int j = 0; j < ret.size(); j++)
      {
        int[] seenArray = ret.get(j);

        if (arrayContentsSame(candidate, seenArray))
        {
          seen = true;
        }
      }

      if (!seen)
      {
        ret.add(candidate);
      }
    }

    return ret;
  }

  private boolean arrayContentsSame(int[] a, int[] b)
  {
    if (a.length != b.length)
    {
      return false;
    }
    else
    {
      for (int i = 0; i < a.length; i++)
      {
        if (a[i] != b[i])
        {
          return false;
        }
      }
    }
    return true;
  }

  // if parents are selected, this will make sure no children are in the vector
  // this is done because it doesn't make sense to have both children and
  // parents in the selected vector
  private void correctSelectedGroupVector()
  {
    Vector<Vector<String>> clone = new Vector<Vector<String>>();
    for (int i = 0; i < selectedGroupStringVector.size(); i++)
    {
      Vector<String> currentAscriptiveGroups = selectedGroupStringVector.get(i);
      Vector<String> clonedAscriptiveGroups = new Vector<String>();

      for (int j = 0; j < currentAscriptiveGroups.size(); j++)
      {
        clonedAscriptiveGroups.add(currentAscriptiveGroups.get(j));
      }

      clone.add(clonedAscriptiveGroups);
    }

    for (int k = 0; k < selectedGroupStringVector.size(); k++)
    {
      Vector<String> currentAscriptiveGroups = selectedGroupStringVector.get(k);
      Vector<String> currentCloneAscriptiveGroups = clone.get(k);

      for (String s : currentAscriptiveGroups)
      {
        DefaultMutableTreeNode d = TreeUtilities.getAscriptiveNode(s, coalitionCreationAscriptiveTree);
        if (d == null)
        {
          System.out.println("s is: " + s);
        }

        Vector<DefaultMutableTreeNode> queue = new Vector<DefaultMutableTreeNode>();
        for (int i = 0; i < d.getChildCount(); i++)
        {
          queue.add((DefaultMutableTreeNode) d.getChildAt(i));
        }

        while (queue.size() > 0)
        {
          DefaultMutableTreeNode popped = queue.get(0);
          queue.remove(popped);
          currentCloneAscriptiveGroups.remove((String) popped.getUserObject());

          for (int j = 0; j < popped.getChildCount(); j++)
          {
            queue.add((DefaultMutableTreeNode) popped.getChildAt(j));
          }
        }
      }
    }

    selectedGroupStringVector = clone;
  }
}














